package com.kx.controller;

import com.kx.exception.AgeException;
import com.kx.exception.MyUserException;
import com.kx.exception.NameException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class MyController {

    @RequestMapping(value = "/some.do")
    public ModelAndView doSome(String name,Integer age) throws MyUserException {  //doGet --service请求处理
        ModelAndView mv = new ModelAndView();
//        try {
        //根据请求参数抛出异常（让框架做try catch）
        if(!"zs".equals(name)){
            throw new NameException("姓名不正确!!!");
        }

        if (age == null || age > 80){
            throw new AgeException("年龄比较大！！！");
        }
//        }catch (Exception e){
//
//        }
        mv.addObject("name", name);
        mv.addObject("age", age);
        mv.setViewName("show");
        return mv;
    }
}
